<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script src="../plugins/healthmobile.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <!--header-->
    <div class="content-header">
        <h1>预约管理
            <small>检查组管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <!--header/-->


    <div class="app-container">
        <div class="box">
            <!--按钮区-->
            <div class="filter-container">
                <el-input placeholder="预约日期/会员姓名/联系电话" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"
                          @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <!--按钮区/-->

            <!--分页数据区-->
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="address" label="预约地址" align="center"></el-table-column>
                <el-table-column prop="memberName" label="会员姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="联系电话" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                <!--<el-table-column label="预约类型" align="center">
                    <template slot-scope="scope">
                        &lt;!&ndash;需要修改&ndash;&gt;
                        <span>{{ scope.row.orderType == '0' ? '电话预约' : '微信预约'}}</span>
                    </template>
                </el-table-column>-->

                <!--<el-table-column label="预约状态" align="center">
                    <template slot-scope="scope">
                        &lt;!&ndash;需要修改&ndash;&gt;
                        <span>{{ scope.row.orderStatus == '0' ? '已到诊' : '未到诊'}}</span>
                    </template>
                </el-table-column>-->
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">确定预约</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">取消预约</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!--分页数据区/-->

            <!--分页条-->
            <div class="pagination-container">
                <el-pagination
                        background
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!--分页条/-->

            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible" v-if="dialogFormVisible">
                    <el-tabs v-model="activeName" type="card">
                        <el-tab-pane label="基本信息" name="first">
                            <el-form ref="dataAddForm" :model="formData" label-position="right"
                                     label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="姓名">
                                            <el-input v-model="formData.name"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="联系电话">
                                            <el-input v-model="formData.telephone"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>

                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="性别">
                                            <el-select v-model="formData.sex">
                                                <el-option label="男" value="0"></el-option>
                                                <el-option label="女" value="1"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>

                                    <el-col :span="12">
                                        <el-form-item label="预约日期">
                                            <el-date-picker type="date"
                                                            placeholder="选择日期"
                                                            v-model="formData.orderDate"
                                                            style="width: 100%;"
                                                            value-format="yyyy-MM-dd">
                                            </el-date-picker>
                                        </el-form-item>
                                    </el-col>
                                </el-row>

                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="身份证号">
                                            <el-input v-model="formData.idCard"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>

                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="地址">
                                            <el-select v-model="formData.region" placeholder="请选择地址">
                                                <el-option v-for="store in storeData"
                                                           :label="store.name"
                                                           :value="store.id">
                                                </el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                        </el-tab-pane>
                        <el-tab-pane label="套餐信息" name="second">
                            <div class="checkScrol">
                                <table class="datatable">
                                    <thead>
                                    <tr>
                                        <th>选择</th>
                                        <th>套餐名称</th>
                                        <th>适用性别</th>
                                        <th>适用年龄</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr v-for="setMeal in setMealData">
                                        <td>
                                            <input :id="setMeal.id" v-model="setMealIds" type="checkbox"
                                                   :value="setMeal.id">
                                        </td>
                                        <td><label :for="setMeal.id">{{setMeal.name}}</label></td>
                                        <td><label :for="setMeal.id">{{setMeal.sex == '0' ? '男':'女'}}</label></td>
                                        <td><label :for="setMeal.id">{{setMeal.age}}</label></td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </el-tab-pane>
                    </el-tabs>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
            <!-- 新增标签弹层/ -->

            <!-- 编辑标签弹层 -->
            <!--<div class="add-form">
                <el-dialog title="编辑检查组" :visible.sync="dialogFormVisible4Edit">
                    <el-tabs v-model="activeName" type="card">
                        <el-tab-pane label="基本信息" name="first">
                            <el-form :model="formData" :rules="rules" ref="editDataForm" label-position="right"
                                     label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="编码" prop="code">
                                            <el-input v-model="formData.code"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="名称" prop="name">
                                            <el-input v-model="formData.name"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>

                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="适用性别">
                                            <el-select v-model="formData.sex">
                                                <el-option label="不限" value="0"></el-option>
                                                <el-option label="男" value="1"></el-option>
                                                <el-option label="女" value="2"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="助记码" prop="helpCode">
                                            <el-input v-model="formData.helpCode"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="说明">
                                            <el-input v-model="formData.remark" type="textarea"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="注意事项">
                                            <el-input v-model="formData.attention" type="textarea"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                        </el-tab-pane>
                        <el-tab-pane label="检查项信息" name="second">
                            <div class="checkScrol">
                                <table class="datatable">
                                    <thead>
                                    <tr>
                                        <th>选择</th>
                                        <th>项目编码</th>
                                        <th>项目名称</th>
                                        <th>项目说明</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr v-for="c in tableData">
                                        <td>
                                            <input :id="c.id" v-model="checkitemIds" type="checkbox" :value="c.id">
                                        </td>
                                        <td><label :for="c.id">{{c.code}}</label></td>
                                        <td><label :for="c.id">{{c.name}}</label></td>
                                        <td><label :for="c.id">{{c.remark}}</label></td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </el-tab-pane>
                    </el-tabs>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>-->
            <!-- 编辑标签弹层/ -->

        </div>
    </div>
</div>
</body>

<script>
    new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称

            pagination: {//分页相关属性
                total: 100,
                pageSize: 10,
                currentPage: 1,
                queryString: null,
            },

            dataList: [],//列表数据

            formData: {},//表单数据

            setMealData: [],//新增和编辑表单中对应的检查项列表数据

            setMealIds: [],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交

            storeData: [],// 门店定位信息

            storeIds: [], // 门店id数组

            dialogFormVisible: false,//控制添加窗口显示/隐藏

            dialogFormVisible4Edit: false//控制编辑窗口显示/隐藏

        },
        // 初始化回调
        created() {
            this.findPage();
        },
        methods: {
            //编辑
            handleEdit() {
                /*
                //校验表单
               this.$refs['editDataForm'].validate((valid) => {
                  if (valid) { //表单校验成功
                     //1.隐藏编辑窗口
                     this.dialogFormVisible4Edit = false;
                     //2.发送ajax请求
                     axios.post("/checkGroup/update/"+this.checkitemIds+".do",this.formData).then((res) =>{
                        if (res.data.flag) { //修改成功
                           //成功提示框
                           this.$message({
                              type:'success',
                              message:res.data.message
                           });

                        } else { //修改失败
                           //失败提示框
                           this.$message.error(res.data.message);

                        }

                     }).finally(() => {
                        //分页查询
                        this.findPage(1); //不使用默认
                     });

                  } else { //表单校验失败
                     //提示框
                     this.$message.error("检验失败,请输入正确再提交!");
                     return false;
                  }

               });*/

            },
            //添加
            handleAdd() {

                // 1.数据校验
                // 判断空校验
                let name = this.formData.name;
                if (!checkParam(name)) {
                    this.$message.error("请输入会员姓名");
                    return false;
                }

                let telephone = this.formData.telephone;
                if (!checkParam(telephone)) {
                    this.$message.error("请输入联系电话");
                    return false;
                }

                // 正则校验
                let idCard = this.formData.idCard;

                if (idCard !== null && idCard !== '' && idCard !== undefined) {

                    if (!checkIdCard(idCard)) {
                        this.$message.error("身份证格式错误,请重新输入");
                        return false;
                    }
                }

                if (!checkTelephone(telephone)) {
                    this.$message.error("联系电话格式有误,请重新输入");
                    return false;
                }

                //2.发送ajax请求,提交参数:checkitemIds和formData
                axios.post(`/order/create/${this.setMealIds}.do`, this.formData).then((res) => {
                    if (res.data.flag) { //添加成功
                        //成功提示框
                        this.$message({
                            type: 'success',
                            message: res.data.message
                        });

                    } else { //添加失败
                        //失败提示框
                        this.$message.error(res.data.message);
                    }
                }).catch().finally(() => {
                    //隐藏添加窗口
                    this.dialogFormVisible = false;
                    //分页查询
                    this.findPage();
                });

            },
            //分页查询
            findPage(isCustom) {
                //0.设置默认当前页
                if (!isCustom) { //传递isCustom参数则不执行默认
                    this.pagination.currentPage = 1;
                }

                //1.设置参数
                let params = {
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString,
                    currentPage: this.pagination.currentPage,
                };

                //2.发送ajax请求
                axios.post("/order/pagination.do", params).then((response) => {
                    //设置列表数据
                    this.dataList = response.data.rows;
                    //设置总页数
                    this.pagination.total = response.data.total;

                });
            },
            // 重置表单
            resetForm() {
                //重置表单数据
                this.formData = {};
            },
            // 弹出添加窗口
            handleCreate() {
                //0.重置表单数据,并默认切换标签为第一个
                this.resetForm();
                this.setMealIds = []; //重置复选框
                this.activeName = 'first'; //重置面板

                //1.修改dialogFormVisible值为true
                this.dialogFormVisible = true;


                //2.发送ajax请求，获取检查项的数据，进行回显
                axios.get("/order/list.do").then((response) => {

                    if (response.data.flag) {//查询成功
                        //回显数据到弹框的"检查项信息"中
                        this.setMealData = response.data.data.setMeals;
                        this.storeData = response.data.data.stores;
                    } else {
                        //查询失败
                        this.$message.error(response.data.message);
                    }
                });
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                this.$confirm('是否确认预约?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //1.确认预约操作
                    axios.get(`/order/edit/${row.id}.do`).then((response) => {
                        this.$message({
                            message: response.data.message,
                            type: response.data.flag === true ? 'success' : 'error'
                        });
                        this.findPage();
                    });
                });
            },
            //切换页码
            handleCurrentChange(currentPage) {
                /*   //设置分页模型数据
                   this.pagination.currentPage = currentPage;
                   //调用分页方法
                   this.findPage(1); //使用当前页*/

            },
            // 删除
            handleDelete(row) {
                this.$confirm('是否取消预约?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //1.确认预约操作
                    axios.get(`/order/delete/${row.id}.do`).then((response) => {
                        this.$message({
                            message: response.data.message,
                            type: response.data.flag === true ? 'success' : 'error'
                        });
                        this.findPage();
                    });
                });
            },
        }
    })
</script>
</html>
